package sistema.servlet.estudiante;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import sistema.excepcion.DAOExcepcion;
import sistema.modelo.Estudiante;
import sistema.negocio.GestionEstudiante;

/**
 * Servlet implementation class EstudianteInsertarServlet
 */
@WebServlet("/EstudianteInsertarServlet")
public class EstudianteInsertarServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public EstudianteInsertarServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub

		Estudiante vo = new Estudiante();
		vo.setNombres(request.getParameter("nombres"));
		vo.setPaterno(request.getParameter("paterno"));
		vo.setMaterno(request.getParameter("materno"));
		vo.setSexo(request.getParameter("sexo"));
		vo.setTipDoc(Integer.parseInt(request.getParameter("tipDoc")));
		vo.setNumDoc(request.getParameter("numDoc"));
		vo.setCorreo(request.getParameter("correo"));
		vo.setPassword(request.getParameter("password"));
		vo.setCelular(request.getParameter("celular"));
			
		GestionEstudiante negocio = new GestionEstudiante();
		try {
			negocio.insertar(vo);
			response.sendRedirect(request.getContextPath()	+ "/EstudianteBuscarServlet");
		} catch (DAOExcepcion e) {
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);
		}
		
	}

}
